<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改CTCP应用')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-app-edit" th:object="${ctcpApp}">
            <h4 class="form-header h4">CTCP应用信息</h4>
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">应用名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">描述：</label>
                <div class="col-sm-8">
                    <input name="description" th:field="*{description}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">类型：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('ctcp_app_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">状态：</label>
                <div class="col-sm-8">
                    <select name="status" class="form-control m-b" th:with="type=${@dict.getType('sys_normal_disable')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{status}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">节点序号：</label>
                <div class="col-sm-8">
                    <input name="nodeId" th:field="*{nodeId}" class="form-control" type="text" required>
                </div>
            </div>
            <h4 class="form-header h4">CTCP计算节点信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/app";
        var typeDatas = [[${@dict.getType('ctcp_node_type')}]];
        var statusDatas = [[${@dict.getType('sys_normal_disable')}]];
        $("#form-app-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-app-edit').serialize());
            }
        }

        $(function() {
            var options = {
                data: [[${ctcpApp.ctcpNodeList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'name',
                    align: 'center',
                    title: '节点名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='ctcpNodeList[%s].name' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'description',
                    align: 'center',
                    title: '节点描述',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='ctcpNodeList[%s].description' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'type',
                    align: 'center',
                    title: '节点类型',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("ctcpNodeList[%s].type", index);
                        return $.common.dictToSelect(typeDatas, value, name);
                    }
                },
                {
                    field: 'status',
                    align: 'center',
                    title: '节点状态',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("ctcpNodeList[%s].status", index);
                        return $.common.dictToSelect(statusDatas, value, name);
                    }
                },
                {
                    field: 'ip',
                    align: 'center',
                    title: 'IP地址',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='ctcpNodeList[%s].ip' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'port',
                    align: 'center',
                    title: '端口',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='ctcpNodeList[%s].port' value='%s'>", index, value);
                        return html;
                    }
				
                }]
            };
            $.table.init(options);
        });

        function addColumn() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            sub.editColumn();
        	
            $("#" + table.options.id).bootstrapTable('insertRow', {
                index: count,
                row: {
                    index: $.table.serialNumber(count),
                    name: "",
                    description: "",
                    type: "",
                    status: "",
                    ip: "",
                    port: ""
        	    }
            });
        }
    </script>
</body>
</html>